<?php
require('config.php');

if(!isset($_SESSION['id_user'])){
	$_SESSION['referer_connexion'] =  "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
	redirectFront('connexion');
}
if(isset($_GET['status'])){
	if(!is_numeric($_GET['status'])) die('bad parameter');
	else{
		if($_GET['status'] == LOCATION_STILL_AVAILABLE){
			if(isset($_GET['id_contact'])){
				if(!is_numeric($_GET['id_contact'])) die('bad parameter');
			}else die('Missing query string');
		}elseif($_GET['status'] == LOCATION_NOT_AVAILABLE){
			if(isset($_GET['id_location'])){
				if(!is_numeric($_GET['id_location'])) die('bad parameter');
			}else die('Missing query string');
		}else die('bad parameter');
	}
}else die('Missing query string');
$page = new rootLayoutPage();

/*$page->setBaliseTitle('Profile');
$page->setDescription('Profile');
$page->addJavaScript('profil-upload-photo.js');
$page->addJavaScript('ajaxUpload.js');*/
$xml_subject = tmxTranslate('subject.mail.xml', REP_XLAT_MAIL);
//-- menu Left show products--------------------------------//
$menu = new layoutMenuLeft();
$menuCategorie = new layoutMenuPage();
$menu->pushMenu($menuCategorie);
$menuPage = new layoutMenuPage();
$menu->pushMenu($menuPage);
$page->setMenuPage($menu);
$bl='';
//-- corps de la page --------//
	if($_GET['status'] == LOCATION_STILL_AVAILABLE){
		$user = modelUser::getIdUser($_GET['id_contact']);
		$mail = new flyLayout(REP_MAIL.'location-still-available.mail.tpl');
		$mail->start();
		//$mail->setVariable('prenom', $prenom);
		$mail->stop();

		$subject = $xml_subject['location_still_available'];

		if(STATUS_EMAIL == 0) {
    		echo $mail;
    	}elseif(STATUS_EMAIL == 1) {
    		monsterMail($user->login, $subject, $mail);
    	}else {
    		echo $mail;
    		monsterMail($user->login, $subject, $mail);
    	}
    	$bl='still';
		//modelMap::validateLocation($_GET['id'],$_GET['idl']);		
		//Persistence::register(PERSIST_MESSAGE, new Message("The location has been validate", Message::INFO));
	}elseif($_GET['status'] == LOCATION_NOT_AVAILABLE){
		modelLocationMap::updateStatusLocation($_GET['id_location'],LOCATION_NOT_AVAILABLE);
		$bl='not';
	}

$tpl_file='validation-location.tpl';
$validation_location = new flyLayout(REP_TPL . $tpl_file);
$validation_location->start();
if($bl != ''){
	$validation_location->showBlock($bl);
}
//$language_folder = $_SESSION['language_code']==language_default?'':'/'.$_SESSION['language_code'];
//$validation_location->setVariable('language_folder', $language_folder);

$validation_location->stop();
$page->setBody($validation_location);
$page->display();

?>